﻿
//Copyright 1997-2009 Syrinx Development, Inc.
//This file is part of the Syrinx Web Application Framework (SWAF).
// == BEGIN LICENSE ==
//
// Licensed under the terms of any of the following licenses at your
// choice:
//
//  - GNU General Public License Version 3 or later (the "GPL")
//    http://www.gnu.org/licenses/gpl.html
//
//  - GNU Lesser General Public License Version 3 or later (the "LGPL")
//    http://www.gnu.org/licenses/lgpl.html
//
//  - Mozilla Public License Version 1.1 or later (the "MPL")
//    http://www.mozilla.org/MPL/MPL-1.1.html
//
// == END LICENSE ==
using System;
using System.Collections.Generic;
using System.Text;
using System.Web.UI;
using System.Web.UI.WebControls;

using Swaf;
using Swaf.BizObj;
using Swaf.Gui;
using Swaf.Gui.AspNet2;
using Swaf.Security;

namespace Syrinx.Gui.AspNet
{
	public class ImagePannerControls : System.Web.UI.UserControl
	{
		protected string m_cssClass;
		protected string m_pannerId;
		protected bool m_bounceControls = false;

		public string CssClass { get { return m_cssClass; } set { m_cssClass = value; } }

		public string PannerId { get { return m_pannerId; } set { m_pannerId = value; } }

		public bool UseBounceControls { get { return m_bounceControls; } set { m_bounceControls = value; } }

		protected override void Render(HtmlTextWriter writer)
		{
			if (!Cmn.IsEmpty(PannerId))
			{
				Control ctl = searchControl(PannerId, Page);
				if (ctl != null)
				{
					if (UseBounceControls)
					{
						writer.Write(string.Format(
	@"<map name='{0}PlayerMap'>
		<area href=""javascript: void getPan('{1}').stop()"" shape='rect' coords='0, 0, 24, 22' alt='Stop'>
		<area href=""javascript: void getPan('{1}').moveAt(-1)"" shape='rect' coords='35, 0, 53, 22' alt='Slow'>
		<area href=""javascript: void getPan('{1}').moveAt(-2)"" shape='rect' coords='67, 0, 89, 22'  alt='Medium'>
		<area href=""javascript: void getPan('{1}').moveAt(-4)"" shape='rect' coords='100, 0, 126, 22' alt='Fast'>
	</map>
	<img border='0' src='/images/PlayerButtons.gif' usemap='#{0}PlayerMap' width='127' height='23' align=bottom>",
						ClientID, ctl.ClientID));
					}
					else
					{
						writer.Write(string.Format(
	@"<table border=0 id='{0}'><tr>
	<td><button onclick=""getPan('{1}').moveMore('left')"" type='button'>&nbsp;&lt;&lt;&nbsp;</button></td>
	<td><button onclick=""getPan('{1}').stop()"" type='button'>Stop</button></td>
	<td><button onclick=""getPan('{1}').moveMore('right')"" type='button'>&nbsp;&gt;&gt;&nbsp;</button></td>
</tr></table>", ClientID, ctl.ClientID));
					}
				}
			}
		}
		protected Control searchControl(string id, Control parent)
		{
			foreach (Control c in parent.Controls)
				if (id.Equals(c.ID))
					return c;
				else
				{
					Control theOne = searchControl(id, c);
					if (theOne != null)
						return theOne;
				}
			return null;
		}

	}
}
